package utils.TestCaseMethods;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.robotium.solo.Solo;
import android.view.KeyEvent;
import android.widget.EditText;
/**
 * 模拟点击软键盘输入
 * @author Administrator
 */
public class Send_SoftKeyboard {
	/**
	 * @param number 以数字组成的字符串：如“123456789”<br>
	 * @param solo
	 * @param editText
	 */
	public static void sendNumber(String number, Solo solo,EditText editText) {
		Pattern p = Pattern.compile("([\\d])");
		Matcher m = p.matcher(number);
		List<String> result = new ArrayList<String>();
		while (m.find()) {
			result.add(m.group());
		}
		
		solo.clickOnView(editText);//输入前，先获取输入框焦点
		for (String s1 : result) {
			int num = Integer.parseInt(s1);
			
			switch (num) {
			case 0:
				solo.sendKey(KeyEvent.KEYCODE_0);
				break;
			case 1:
				solo.sendKey(KeyEvent.KEYCODE_1);
				break;
			case 2:
				solo.sendKey(KeyEvent.KEYCODE_2);
				break;
			case 3:
				solo.sendKey(KeyEvent.KEYCODE_3);
				break;
			case 4:
				solo.sendKey(KeyEvent.KEYCODE_4);
				break;
			case 5:
				solo.sendKey(KeyEvent.KEYCODE_5);
				break;
			case 6:
				solo.sendKey(KeyEvent.KEYCODE_6);
				break;
			case 7:
				solo.sendKey(KeyEvent.KEYCODE_7);
				break;
			case 8:
				solo.sendKey(KeyEvent.KEYCODE_8);
				break;
			case 9:
				solo.sendKey(KeyEvent.KEYCODE_9);
				break;
			}
		}
	}
}
